<template>
  <svg
    :class="svgClass"
    aria-hidden="true"
    :fill="color"
    :style="{ width: width, height: height, color: color }"
  >
    <use :xlink:href="iconName"></use>
  </svg>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'

export default defineComponent({
  name: 'svg-icon',
  props: {
    iconClass: {
      type: String,
      required: true
    },
    className: {
      type: String
    },
    width: {
      type: String,
      default: '22px'
    },
    height: {
      type: String,
      default: '22px'
    },
    color: {
      type: String
    }
  },
  setup(props) {
    const iconName = computed(() => `#icon-${props.iconClass}`)
    const svgClass = computed(() => {
      if (props.className) {
        return 'svg-icon ' + props.className
      } else {
        return 'svg-icon'
      }
    })
    return { iconName, svgClass }
  }
})
</script>

<style scoped lang="less">
.svg-icon {
  /* width: 16px;
  height: 16px; */
  /* vertical-align: -0.15em; */
  fill: currentColor;
  overflow: hidden;
}
</style>
